//+--------------------------------------------------------------------------------
//| Copyright (c) 2012 - 2013 ### an.vuongngocduy
//| This file is a part of Compact Game Engine (CGE)
//+--------------------------------------------------------------------------------
#ifndef __CGE_FILESTREAM_H__
#define __CGE_FILESTREAM_H__

#include <stdio.h>
#include "cgeEnums.h"
#include "cgeStream.h"
#include "cgeString.h"

using namespace cge::std;

namespace cge
{
	namespace io
	{
		//! Provide interface to read/write data from file as input/output stream
		class FileStream : public Stream
		{
		public:
			//! Constructor. Open a file with specified mode
			FileStream(const String& filePath, EFileOpenMode mode);


			//! Destructor
			~FileStream();

			
			//! Return loaded file's path
			const String& GetFilePath() const;


			//! Cast to base Stream class
			operator Stream&() const;


		protected:
			//! @implements Stream::finalize()
			virtual b8 finalize();


			//! @implements Stream::seek()
			virtual b8 seek(u32 offset, b8 fromBeginning);


			//! @implements Stream::size()
			virtual u32 size();
			

			//! @implements Stream::position()
			virtual u32 position();


			//! @implements Stream::read()
			virtual u32 read(u8* dst, u32 count); 
			

			//! @implements Stream::write()
			virtual u32 write(u8* src, u32 count);
	
	
		protected:			
			FILE* mFile;
			u32 mFileSize;
			String mFilePath;
			EFileOpenMode mMode;
		};
	}
}

#endif//__CGE_FLESTREAM_H__